package com.noyes4j.customer.controller;

import com.noyes4j.common.core.controller.BaseController;
import com.noyes4j.common.core.domain.R;
import com.noyes4j.common.core.page.TableDataInfo;
import com.noyes4j.common.log.annotation.OperLog;
import com.noyes4j.common.log.enums.BusinessType;
import com.noyes4j.common.utils.poi.ExcelUtil;
import com.noyes4j.customer.domain.SysCustomer;
import com.noyes4j.customer.service.ISysCustomerService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName SysCustomerController
 * @Description: TODO
 * @Author zhaoweiqin
 * @Date 2021/1/29
 * @Version V1.0
 **/
@Controller
@RequestMapping("/system/customer")
public class SysCustomerController extends BaseController {


    private String prefix = "system/customer";

    @Autowired
    private ISysCustomerService sysCustomerService;

    @GetMapping()
    public String customer()
    {
        return prefix + "/customer";
    }

    /**
     * 查询客户列表
     */
/*    @RequiresPermissions("system:customer:list")*/
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysCustomer sysCustomer)
    {
        startPage();
        List<SysCustomer> list = sysCustomerService.selectSysCustomerList(sysCustomer);
        return getDataTable(list);
    }

    /**
     * 导出客户列表
     */

    @PostMapping("/export")
    @ResponseBody
    public R export(SysCustomer sysCustomer)
    {
        List<SysCustomer> list = sysCustomerService.selectSysCustomerList(sysCustomer);
        ExcelUtil<SysCustomer> util = new ExcelUtil<SysCustomer>(SysCustomer.class);
        return util.exportExcel(list, "customer");
    }

    /**
     * 新增客户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户
     */

    @OperLog(title = "客户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public R addSave(SysCustomer sysCustomer)
    {
        return toAjax(sysCustomerService.insertSysCustomer(sysCustomer));
    }

    /**
     * 修改客户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysCustomer sysCustomer = sysCustomerService.selectSysCustomerById(id);
        mmap.put("sysCustomer", sysCustomer);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户
     */

    @OperLog(title = "客户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public R editSave(SysCustomer sysCustomer)
    {
        return toAjax(sysCustomerService.updateSysCustomer(sysCustomer));
    }

    /**
     * 删除客户
     */
    @OperLog(title = "客户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public R remove(String ids)
    {
        return toAjax(sysCustomerService.deleteSysCustomerByIds(ids));
    }

}
